<template>
  <div class="control-item">
    <div class="control-header">
      <span class="control-name">专题</span>
      <span @click="showBeautyBox = true">组件美化</span>
    </div>
    <div class="control-body">
      <div class="control-section" v-show="styleType == 1">
        <!-- 模板样式 -->
        <div class="control-item">
          <div class="control-title">模板样式</div>
          <div class="control-content">
            <div class="example-list">
              <div
                class="example-item"
                v-for="(item, index) in exampleList"
                @click="setStyleType(item)"
                :class="styleType == item.value ? 'active' : ''"
                :key="index"
              >
                <i class="iconfont" :class="item.icon" />
              </div>
            </div>
          </div>
        </div>
        <!-- 显示行数 -->
        <div class="control-item show-lines">
          <div class="control-title flex-between">
            <span>显示行数</span>
            <span class="reset" @click="resetItem('lineNum')">重置</span>
          </div>
          <div class="control-content">
            <a-select
              :default-value="params.params.lineNum"
              @change="
                (e) => {
                  setWithActionItem(e, 'lineNum');
                }
              "
              class="justify-select"
            >
              <a-select-option :value="1"> 1 </a-select-option>
              <a-select-option :value="2"> 2 </a-select-option>
            </a-select>
          </div>
        </div>
        <!-- 图片设置 -->
        <uploadImg
          :uploadImg="params.params.topPicImg"
          @uploadSuccess="uploadSuccess"
          @deleteImg="deleteImg"
        ></uploadImg>
        <!-- 字体配置 -->
        <fontControl
          :fontData.sync="params.params.css"
          @resetFontCss="resetFontCss"
          :showAlign="false"
        ></fontControl>
      </div>
      <div class="control-section" v-show="styleType == 2">
        <!-- 模板样式 -->
        <div class="control-item">
          <div class="control-title">模板样式</div>
          <div class="control-content">
            <div class="example-list">
              <div
                class="example-item"
                v-for="(item, index) in exampleList"
                @click="setStyleType(item)"
                :class="styleType == item.value ? 'active' : ''"
                :key="index"
              >
                <i class="iconfont" :class="item.icon" />
              </div>
            </div>
          </div>
        </div>
        <!-- 展示分类 -->
        <div class="control-item show-lines">
          <div class="control-title flex-between">
            <span>展示分类</span>
            <span class="reset" @click="resetItem('showTabs')">重置</span>
          </div>
          <div class="control-content">
            <a-select
              :default-value="params.params.showTabs"
              @change="
                (e) => {
                  setWithActionItem(e, 'showTabs');
                }
              "
              class="justify-select"
            >
              <a-select-option :value="1"> 展示 </a-select-option>
              <a-select-option :value="0"> 不展示 </a-select-option>
            </a-select>
          </div>
        </div>
        <!-- 分割线样式 -->
        <div class="control-item split-line">
          <div class="control-title flex-between">
            <span>分割线样式</span>
            <span class="reset" @click="resetItem('splitLine')">重置</span>
          </div>
          <div class="control-content">
            <div class="line-style">
              <a-input
                type="color"
                class="color-select"
                v-model="params.params.splitLine.borderColor"
              />
              <a-input
                type="text"
                class="color-input"
                v-model="params.params.splitLine.borderColor"
              />
              <a-input
                type="number"
                class="color-width"
                :min="1"
                v-model="params.params.splitLine.borderWidth"
              />
            </div>
          </div>
        </div>
      </div>
    </div>

    <!-- 组件美化 -->
    <comBeautyBox
      :showBeautyBox="showBeautyBox"
      @handleBack="showBeautyBox = false"
    >
      <div>
        <!-- 背景配置 -->
        <bgControl :backgroudData="params.moduleCss"></bgControl>
        <!-- 间距控制组件 -->
        <spaceControl
          :spaceData.sync="params.moduleCss"
          @resetSpace="resetSpace"
          @resetMp="resetMp"
        ></spaceControl>
      </div>
    </comBeautyBox>
  </div>
</template>

<script>
import { diyTopPic } from "@/components/DiyNew/diy/dataConfig/config.js";

import uploadImg from "@/components/DiyNew/uploadImg/index.vue";
import bgControl from "@/components/DiyNew/diy/baseControl/bgControl/index.vue";
import fontControl from "@/components/DiyNew/diy/baseControl/fontControl/index.vue";
import comBeautyBox from "@/components/DiyNew/diy/comBeautyBox/comBeautyBox.vue";
import spaceControl from "@/components/DiyNew/diy/baseControl/spaceControl/index.vue";

export default {
  name: "diyTopPicControl",
  components: {
    bgControl,
    fontControl,
    uploadImg,
    comBeautyBox,
    spaceControl,
  },
  props: {
    params: {
      type: Object,
      default: {},
    },
  },
  data() {
    return {
      showBeautyBox: false,
      exampleList: [
        {
          icon: "icon-tupian",
          type: "模板1",
          value: "1",
        },
        {
          icon: "icon-liebiao",
          type: "模板2",
          value: "2",
        },
      ],
    };
  },
  watch: {},
  computed: {
    styleType: {
      get() {
        return this.params.params.styleType || "1";
      },
    },
  },
  methods: {
    // 设置样式
    setStyleType(item) {
      this.$setWithAction(this.params, "styleType", item.value);
    },
    setWithActionItem(e, key) {
      this.$setWithAction(this.params, key, e);
    },
    // 上传图片成功回调
    uploadSuccess(e) {
      this.setWithActionItem(e.val, "topPicImg");
      console.log(this.params);
    },
    // 删除图片回调
    deleteImg(e) {
      this.setWithActionItem("", "topPicImg");
    },
    // 重置文字设置
    resetFontCss() {
      let data = Object.assign({}, diyTopPic);
      this.$set(this.params.params, "css", data.params.css);
    },
    // 点击重置按钮
    resetItem(type) {
      let data = Object.assign({}, diyTopPic);
      this.$set(this.params.params, type, data.params[type]);
    },
    // 重置圆角
    resetSpace(e) {
      let type = e.type;
      console.log(type);
      this.$set(this.params.moduleCss, type, 0);
    },
    // 重置边距
    resetMp() {
      this.$set(this.params.moduleCss, "margin", 0);
      this.$set(this.params.moduleCss, "padding", 0);
    },
  },
};
</script>

<style lang="scss" scoped>
.control-item {
  width: 100%;
  height: 100%;
  margin: 0 auto;
  .control-header {
    width: 100%;
    height: 48px;
    background: #ffffff;
    border-bottom: 1px solid #f0f2f5;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 24px 14px 24px;
    span {
      font-size: 12px;
      color: #8c8c8c;
    }
    .control-name {
      font-size: 14px;
      font-weight: 600;
      color: #000000;
    }
    span:nth-child(2) {
      cursor: pointer;
    }
  }
  .control-body {
    width: 100%;
    padding-bottom: 20px;
    .control-section {
      width: 228px;
      margin: 0 auto;
      text-align: center;
      .control-item {
        width: 100%;
        .control-title {
          padding: 24px 0 14px 0;
          font-size: 12px;
          color: #000000;
          text-align: left;
        }
        .control-content {
          .example-list {
            width: 100%;
            display: flex;
            flex-wrap: wrap;
            .example-item {
              width: 70px;
              height: 70px;
              background: #f6f7f9;
              border-radius: 4px;
              margin-right: 6px;
              margin-bottom: 6px;
              display: flex;
              justify-content: center;
              align-items: center;
              cursor: pointer;
              overflow: hidden;
              .iconfont {
                font-size: 60px;
              }
            }
            .example-item:last-child {
              margin-right: 0;
            }
            .active {
              border: 2px solid #1890fc;
            }
          }
        }
      }
      .show-lines,
      .start-section {
        .flex-between {
          display: flex;
          justify-content: space-between;
          .reset {
            font-size: 12px;
            color: #9e9e9e;
            cursor: pointer;
          }
        }
        .control-content {
          display: flex;
          align-items: center;
          .justify-select {
            width: 100%;
            height: 100%;
            ::v-deep .ant-select-selection--single {
              height: 100%;
              border: 0 none;
              background: #f2f2f2;
            }
            ::v-deep .ant-select-selection__rendered {
              line-height: 40px;
            }
          }
        }
      }
      .split-line {
        .flex-between {
          display: flex;
          justify-content: space-between;
          .reset {
            font-size: 12px;
            color: #9e9e9e;
            cursor: pointer;
          }
        }
        .control-content {
          .line-style {
            display: flex;
            align-items: center;
            .color-select {
              width: 48px;
              height: 40px;
              background: #f6f7f9;
              border-radius: 4px;
              margin-right: 8px;
            }
            .color-input {
              width: 86px;
              height: 40px;
              background: #f6f7f9;
              border-radius: 4px;
              margin-right: 8px;
            }
            .color-width {
              width: 78px;
              height: 40px;
              background: #f6f7f9;
              border-radius: 4px;
            }
          }
        }
      }
    }
  }
}
</style>
